package com.example.springbootlearn.conditional;

import com.example.springbootlearn.annotation.EnableServerBootStrap;
import com.example.springbootlearn.annotation.Server;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;

import javax.xml.transform.Source;
import java.util.stream.Stream;

/**
 * @author caiji Mr. Li
 * @date 2019/10/19 16:34
 */
@ComponentScan(basePackageClasses = ConditionalMessageBootStrap.class)
public class ConditionalMessageBootStrap {

    public static void main(String[] args) {
        System.setProperty("language", "English");

        //构建Annotation配置驱动Spring上下文
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
        //注册当前引导类(被@Configuration标注)到Spring的上下文中
        context.register(ConditionalMessageConfiguration.class);
        //启动上下文
        context.refresh();
        //获取名称为“helloWorld”的bean对象
        String message = context.getBean("message", String.class);
        System.out.println("bean  = " + message);

        //构建Annotation配置驱动Spring上下文
//        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
//        System.out.println("当前spring应用上下文中所有注册的Bean");
//        Stream.of(context.getBeanDefinitionNames())
//                .map(name->"\t"+name)
//                .forEach(System.out::println);
//        context.close();
    }
}
